package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.error.BusinessException;
import com.goods.common.model.business.Product;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    //获取物资列表 及条件搜索
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam Map<String,Object> queryMap){
        PageVO<ProductVO> productList = productService.findProductList(queryMap);
        return ResponseBean.success(productList);
    }
    //添加物资资料
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated ProductVO productVO){
        productService.add(productVO);
        return ResponseBean.success();
    }
    //编辑物资资料
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductVO productVO = productService.edit(id);
        return ResponseBean.success(productVO);
    }
    //更新物资资料
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO) throws BusinessException {
        productService.update(id,productVO);
        return ResponseBean.success();
    }
    //移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id) throws BusinessException {
        productService.remove(id);
        return ResponseBean.success();
    }
    //从回收站中恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id) throws BusinessException {
        productService.back(id);
        return ResponseBean.success();
    }
    //删除该物资资料
    @PutMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) throws BusinessException {
        productService.delete(id);
        return ResponseBean.success();
    }
    //物资资料的审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id) throws BusinessException {
        productService.publish(id);
        return ResponseBean.success();
    }
    //获取所有的物资列表  及分页列表
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam Map<String,Object> queryMap){
        PageVO<ProductStockVO> products = productService.findProducts(queryMap);
        return ResponseBean.success(products);
    }
    //获取所有物资的库存信息饼状图
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(){
        List<ProductStockVO> products = productService.findAllStocks();
        return ResponseBean.success(products);
    }
    //查询某个物资的库存柱状图
    @GetMapping("/findProductStocks")
    public ResponseBean findProductStocks(@RequestParam Map<String,Object> queryMap){
        PageVO<ProductStockVO> products = productService.findProductStocks(queryMap);
        return ResponseBean.success(products);
    }
}
